package com.kchouse.myadapter;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.kchouse.MainActivity;
import com.kchouse.R;
import com.kchouse.bean.CashRecordItem;
import com.kchouse.bean.OrderEvaItem;
import com.kchouse.common.API;
import com.kchouse.common.MyHttpCycleContext;
import com.kchouse.common.ToastUtils;

import java.util.ArrayList;

import cn.finalteam.okhttpfinal.BaseHttpRequestCallback;
import cn.finalteam.okhttpfinal.HttpRequest;
import cn.finalteam.okhttpfinal.RequestParams;

public class CashRecordAdapter extends RecyclerView.Adapter<CashRecordAdapter.ViewHolder> {

    private ArrayList<CashRecordItem> datas;
    private Context context;


    public CashRecordAdapter(Context context, ArrayList<CashRecordItem> datas) {
        this.datas = datas;
        this.context = context;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {

        View view = null;
        ViewHolder vh = null;
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.lv_integral_item, viewGroup, false);
        vh = new ViewHolder(view);
        return vh;
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {


        final CashRecordItem item = datas.get(position);

        if (item.getStatus().equals("CONSUME"))//DRAW-领取，CONSUME-消费
        {
            viewHolder.tv_merchantName.setText(item.getMerchantName());
            viewHolder.tv_suitName.setText(item.getSuitName());
            viewHolder.tv_useStatus.setText("-"+(item.getNum()*10));
            viewHolder.tv_useStatus.setTextColor(context.getResources().getColor(R.color.colorred));
        } else {
            viewHolder.tv_merchantName.setText(item.getSource());
            viewHolder.tv_suitName.setText("获得现金券10元"+item.getNum()+"张");
            viewHolder.tv_useStatus.setText("+"+(item.getNum()*10));
            viewHolder.tv_useStatus.setTextColor(context.getResources().getColor(R.color.text_main));
        }
           viewHolder.tv_createTime.setText(item.getCreateTime().substring(0,10));
    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_merchantName;
        public TextView tv_createTime;
        public TextView tv_suitName;
        public TextView tv_useStatus;

        public ViewHolder(View view) {
            super(view);
            tv_merchantName = (TextView) view.findViewById(R.id.tv_merchantName);
            tv_createTime = (TextView) view.findViewById(R.id.tv_createTime);
            tv_suitName = (TextView) view.findViewById(R.id.tv_suitName);
            tv_useStatus = (TextView) view.findViewById(R.id.tv_useStatus);
        }
    }


}
